<%--
  Created by IntelliJ IDEA.
  User: zll
  Date: 2018/5/30
  Time: 12:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>活动列表</title>

    <jsp:include page="../comm/comm.jsp"/>
    <link href="/css/upload.css" rel="stylesheet"/>
    <script type="text/javascript" charset="utf-8" src="/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/myjs/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/myjs/zh-cn.js"> </script>
    <script src='/myjs/mip-ueditor.min.js' charset="utf-8"></script>
    <%--<link rel="stylesheet" type="text/css" href="//mipcache.bdstatic.com/static/v1/mip.css">--%>
    <script src="/myjs/upload.js"></script>
</head>
<body>
<div class="layui-form" action="">

    <div class="layui-inline">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline" style="width: 200px;">
            <input type="text" name="" autocomplete="off" class="layui-input" id="startDate">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline" style="width: 200px;">
            <input type="text" name="" autocomplete="off" class="layui-input" id="endDate">
        </div>
    </div>
    <input type="hidden" id="id">
    <div class="layui-inline">
        <div class="layui-input-inline" style="width: 100px;">
            <button class="layui-btn" lay-filter="formDemo" onclick="modifyDate()">确定修改</button>
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 20px">
        <label class="layui-form-label">缩略图(<span style="color: red">建议693px*363px</span>)</label>
        <div class="layui-input-block">
            <div class="image-box clear" id="thumbSelect">
                <input name="goodsDetailJson" id="thumbJsonVal" value="${data.thumb}" type="hidden"/>
                <div id="thumb" value="${data.thumb}"></div>
                <section class="upload-section">
                    <div class="upload-btn"></div>
                    <input type="file" id="thumbJson" value=""
                           accept="image/jpg,image/jpeg,image/png,image/bmp"
                           multiple="multiple"/>
                </section>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">页面标题</label>
        <div class="layui-input-block">
            <input type="text" name="title"  id="pagetitle" required  lay-verify="required" placeholder="请输入页面标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title"  id="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <div id="editor" type="text/plain" style="width:100%;height:300px;"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-filter="formDemo" onclick="modifytitle()">立即提交</button>
        </div>
    </div>
</div>



<script type="text/html" id="operate">
    <button class="layui-btn layui-btn-sm" onclick="modify('{{d.id}}')">详情</button>
</script>
<script type="text/html" id="status">
    {{#  if(d.num < 3){ }}
    <span class="layui-badge">进行中</span>
    {{#  } else { }}
    <span class="layui-badge layui-bg-gray">已完成</span>
    {{#  } }}
</script>
<script type="text/javascript">
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
            return '/ueditor/imgUpload';
            //'http://localhost:8080/imgUpload';为方法imgUpload的访问地址
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }
</script>

<script>
    var ue = UE.getEditor('editor');
    var activityId=getQueryString("activityId");
    $("#thumbJson").ajaxImageUpload({
        url: '/pic/upload', //上传的服务器地址
        maxNum: 1, //允许上传图片数量
        zoom: true, //允许上传图片点击放大
        allowType: ["gif", "jpeg", "jpg", "bmp", 'png'], //允许上传图片的类型
        maxSize: 1, //允许上传图片的最大尺寸，单位M,
        hidenInputName:"thumbimg",
        success: function (data) {

        },
        error: function (e) {
            console.log(e);
        }
    }, $("#thumbSelect"));

    function  initData(data) {
        if(!data){
            return "";
        }
        var datas=data.split(",");
        var html="";
        for(var i=0;i<datas.length;i++){
            html+='<section class="image-section"><div class="image-shade"></div><div class="image-delete"></div>'+
                '<img class="image-show" src="/upload/'+datas[i]+'" /><input id="src" name="src" value="" type="hidden" /></section>'
        }
        return html;
    }
    function  modifyDate() {
       var startDate=$("#startDate").val();
       var endDate=$("#endDate").val();
       config.commPost("/role/saveDate",{startDate:startDate,endDate:endDate,type:"huodong"},function (data) {
           alert("成功");
       });
    }
    function  modifytitle() {
        var title=$("#title").val();
        var content=UE.getEditor('editor').getContent();
        var startDate=$("#startDate").val();
        var endDate=$("#endDate").val();
        var pagetitle=$("#pagetitle").val();
        var id=$("#id").val();
        var thumbImg=$("#thumbSelect").find("img.image-show");
        if(thumbImg.length==0){
            alert("请上传缩略图");
            return;
        }
        config.commPost("/role/saveXuan",{id:id,pagetitle:pagetitle,type:type,title:title,content:content,pictures:getName(thumbImg[0].src),startDate:startDate,endDate:endDate},function (data) {
            alert("成功")
            location.href="/page/role/listactivitys?type=4";
        });
    }

    function  getName(src) {
        var names=src.split("/");
        return names[4];
    }
    var type=getQueryString("type");
    function modify(id){
        config.openLayer("助力详情","/page/role/listuserzhuli?taskId="+id);


         //location.href="/page/role/listusersigns?openid="+id;
    }
    function deletes(id){
        //eg1
        layer.confirm('确认删除?', {icon: 3, title:'提示'}, function(index){
            config.commPost("/tasks/delete.json",{id:id},function (data) {
                alert("成功");
                location.reload();
            })

            layer.close(index);
        });
    }
    layui.use(['table','laydate'], function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#startDate' //指定元素
        });
        laydate.render({
            elem: '#endDate' //指定元素
        });

        // config.commGet("/role/getDates?type=huodong",{},function (data) {
        //     $("#startDate").val(data.startDate);
        //     $("#endDate").val(data.endDate);
        // })
       //alert(activityId);
        var  url="/role/getXuan?id="+activityId;
        if(activityId==null)
            url="/role/getXuan";
        config.commGet(url,{},function (data) {
            if(data==null)
                return;
            UE.getEditor('editor').setContent(data.content)
            $("#id").val(data.id);
            $("#title").val(data.title);
            ///$("#content").val(data.content);
            $("#startDate").val(data.startDate);
            $("#endDate").val(data.endDate);
            $("#pagetitle").val(data.pagetitle);
           // alert(data.thumb);
            $("#thumbSelect").prepend(initData(data.pictures));
        })
        var table = layui.table;


    });
    function getQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
</script>
</body>
</html>
